import {
  Component,
  OnInit,
  ViewEncapsulation,
  ChangeDetectionStrategy,
  AfterViewInit,
  Renderer2,
  ElementRef,
  TemplateRef,
  ViewChild,
} from '@angular/core';
import { DatatableService } from './datatable.service';

@Component({
  selector: 'thead[lv-thead], thead[lvThead], thead:not(.lv-table-thead)',
  exportAs: 'lvThead',
  templateUrl: './thead.component.html',
  styles: [],
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TheadComponent implements OnInit, AfterViewInit {
  // 输入输出属性
  @ViewChild('contentTemplate', { static: true }) templateRef: TemplateRef<void>;

  // 外部可访问变量
  _parentComponent;

  constructor(
    private _elementRef: ElementRef,
    private renderer: Renderer2,
    private datatableService: DatatableService,
  ) {
    this._parentComponent = this.datatableService.getParentComponent();
    if (this._parentComponent) {
      this._parentComponent.setTheadComponent(this);
    }
  }

  ngOnInit(): void {}

  ngAfterViewInit(): void {
    if (this._parentComponent) {
      const _nativeElement = this._elementRef.nativeElement;
      this.renderer.removeChild(this.renderer.parentNode(_nativeElement), _nativeElement);
    }
  }
}
